//		ID : Xerxes
//      "I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define tp pair< int, pair<int,int> >
#define mmk( x, y , z ) mk( x, mk( y, z ) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
int k;
int n; //number of lights
int m; //number of switch
vector<int> board_mask;
int dist[ 1<<16 ];

inline void show_msk(int msk){
	for(int i=0 ; i<n; ++i ){
		cout<<(msk&(1<<i) ? 1 : 0 );
	}
	cout<<"\n";
}

inline void Read(){
	CI(n);
	CI(m);
	board_mask.assign(m,0);
	fo(i,0,m){
		int x;
		fo(j,0,n){
			CI(x);
			if(x==0)continue;
			board_mask[i]|= (1<<j);
		}
	}
}
inline void ini(){
	for(int i=0,j=1<<16; i<j;++i){
		dist[i]=(int)1023456789;
	}
}

inline void Proc(){
	ini();
	queue< int > q;
	q.push( 0 );
	dist[0]=0;
	
	while( q.empty()==false ){
			int light_mask = q.front();
			//show_msk(light_mask);
			q.pop();
			fo(s,0,m){
				int current_board_mask = board_mask[s];
				int now_light_mask = light_mask ^ current_board_mask;
				if( dist[ light_mask ]+1 < dist[ now_light_mask ] ){
					q.push( now_light_mask );
					dist[ now_light_mask ] = dist[ light_mask ]+1;
				}
			}
	}
	int M=0;
	for(int i=0; i<n; ++i ){
		M|=(1<<i);
	}
	
	if( dist[M] < (int)1023456789 ){
		printf("Case %d: %d\n",k,dist[M]);
	}
	else{
		printf("Case %d: IMPOSSIBLE\n",k);
	}
	
}
int main(){
    #ifndef ONLINE_JUDGE
        freopen("in","rt",stdin);
    #endif
    int cases=1;
    for( CI(cases),k=1 ; cases ; --cases,++k ){
        Read();
        Proc();
    }

return 0;
}


